package day11.gec.dql3;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class MultipleQuery2 {
	public static void main(String[] args) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		
		try(
			Connection conn = DriverManager.getConnection("jdbc:mysql:///hrm", "root", "root");	
			Statement st = conn.createStatement();	
			ResultSet rs = st.executeQuery("select * from t_user");
			){
			//返回结果集 遍历 
			while(rs.next()) {
				//获取列值
				/*
				 Object id = rs.getObject(1);//传的是列的索引，如果表的列过多，这将容易数错了 2）Object的数据还得强转，不方便
				 Object name = rs.getObject(2);
				 Object password = rs.getObject(3);
				 */
				int id = rs.getInt(1);
				String name = rs.getString("name");
				String password = rs.getString("password");
				System.out.println(id + ":" + name + ":" + password);
				System.out.println("------------------");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
